package com.zk.babala.util;

import com.zk.babala.BabalaApp;

import java.io.IOException;
import java.io.InputStream;

import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.CharsetUtil;

/**
 * @Author: zhangke
 * @Date: 2025/8/20 16:59
 */
public class ScriptUtil {
    private static String fullScreenScripts = null;
    private static String mgtvScripts = null;

    public static String getFullScreenScripts() {
        if (fullScreenScripts == null) {
            fullScreenScripts = readeScript("fullscreen_script.js");
        }
        return fullScreenScripts;
    }


    public static String getMgtvScripts() {
        if (mgtvScripts == null) {
            mgtvScripts = readeScript("mgtv_script.js");
        }
        return mgtvScripts;
    }

    private static String readeScript(String name) {
        InputStream inputStream = null;
        try {
            // 从assets目录读取JavaScript文件；
            inputStream = BabalaApp.getContext().getAssets().open(name);
            return IoUtil.read(inputStream, CharsetUtil.CHARSET_UTF_8);

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        return "";
    }
}
